#include "Player.hh"
#include "Vector3.hh"

namespace plato {

Player::Player(Domain *domain, VarID parent, PlatoVariableSyncType sync_type)
  : StructVariable(domain, parent, sync_type),
    health(domain->New<Uint32>(sync_type)),
    pos(domain->New<Vector3>(sync_type)) {
  }

Player::~Player() {}

auto Player::New(Domain *domain, VarID parent, PlatoVariableSyncType sync_type) -> std::shared_ptr<Player> {
  return plato::make_shared<Player>(domain->mem_block(), domain, parent, sync_type);
}

auto Player::serialize(PlatoStream &stream) -> bool {
  stream << id();
  health->serialize(stream);
  pos->serialize(stream);
  return true;
}

auto Player::deserialize(PlatoStream &stream) -> bool {
  stream.skip(sizeof(VarID));
  health->deserialize(stream);
  pos->deserialize(stream);
  return true;
}

auto Player::copy(Variable *other) -> void {
  auto *ptr = dynamic_cast<Player *>(other);
  if (!ptr) { return; }
  health->copy(ptr->health.get());
  pos->copy(ptr->pos.get());
}

auto Player::object_size() -> std::size_t {
  return sizeof(Player);
}

auto Player::copy_default() -> void {
  health->copy_default();
  pos->copy_default();
}

auto Player::complete_prototype() -> void { copy_default(); }

auto Player::get_fixed_mem_size() -> std::size_t {
  std::size_t total_size = sizeof(Player);
  total_size += sizeof(Uint32);
  total_size += Vector3::get_fixed_mem_size();
  return total_size;
}

}

